// pages/pay/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    topicData: {},
    money: 1,
    loading:0,
    lastpage:0,
    lists:[],
    moneyList: [0.1, 1, 5, 10, 15, 20, 30, 35, 50],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.topic_id = options.id ? options.id : 83642;
    this.getTopic();
    this.getlist();
    //this.pay();
  },

  getTopic() {
    var that = this;
    app.api('topic/detail', {
      id: that.data.topic_id
    }, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return false;
      }
      that.setData({ topicData: res.data });
    })
  },

  getlist() {
    var that = this;
    if (this.data.loading == 1 || this.data.lastpage == 1) {
      return false;
    }
    this.data.loading = 1;
    app.api('topic_pay/get', {
      topic_id: that.data.topic_id,
      order: "id desc",
      page: that.data.page,
      limit: 50,
    }, function (res) {
      that.data.loading = 0;
      if (res.code != 200) {
        app.alert(res.msg);
        return false;
      }
      if (res.data.list.length == 0) {
        that.data.lastpage = 1;
      }
      // console.log(that.data.lists);
      that.setData({ lists: that.data.lists.concat(res.data.list) });
      that.data.page++;
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getlist();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})